package com.etcfg.etlaunch.ui;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.etcfg.etlaunch.ServerStatus.Player;

public class PlayersTableModel extends AbstractTableModel {

	private static final String[] columnNames = { "Name", "XP", "Ping" };

	private List<Player> players = new ArrayList<Player>();

	@Override
	public int getColumnCount() {
		return columnNames.length;
	}

	@Override
	public int getRowCount() {
		return players.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Player player = players.get(rowIndex);
		if (columnIndex == 0) {
			return player.getName();
		} else if (columnIndex == 1) {
			return player.getXp();
		}
		return player.getPing();
	}

	public List<Player> getPlayers() {
		return players;
	}

	public void setPlayers(List<Player> players) {
		this.players = players;
		fireTableDataChanged();
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		if (columnIndex == 0) {
			return String.class;
		}
		return Integer.class;
	}

	@Override
	public String getColumnName(int column) {
		return columnNames[column];
	}

}
